﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.Silverlight.Library.RichContentService;

namespace FRL.DebtChased.Silverlight.Library
{

	/// <summary>
	/// Declaration of ClientSearchResultsWnd class
	/// Child window for selecting a client from a list of clients
	/// </summary>
	public partial class ClientSearchResultsWnd : ChildWindow
	{

		/////////////////////////////////////////////////////////////
		// Attributes

		private int m_iSelectedClientId = 0;
		public int SelectedClientId
		{
			get { return m_iSelectedClientId; }
		}

		/////////////////////////////////////////////////////////////
		// Construction

		public ClientSearchResultsWnd(List<ClientSummaryTransport> results)
		{

			// Load xaml resources
			InitializeComponent();

			// Load the list
			lstClient.ItemsSource = results;

			// Setup controls
			_setupControls();

		}

		/////////////////////////////////////////////////////////////
		// Event Handlers

		private void OKButton_Click(object sender, RoutedEventArgs e)
		{

			// Get the selected client
			ClientSummaryTransport selected = lstClient.SelectedValue as ClientSummaryTransport;
			m_iSelectedClientId = selected.ClientId;

			// Close dialog
			this.DialogResult = true;
		}

		private void CancelButton_Click(object sender, RoutedEventArgs e)
		{

			// Close dialog
			this.DialogResult = false;

		}

		private void lstClient_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{

			// Setup controls
			_setupControls();

		}

		/////////////////////////////////////////////////////////////
		// Operations

		private void _setupControls()
		{

			// Enable/disable controls
			OKButton.IsEnabled = (lstClient.SelectedIndex != -1);

		}

	}

}

